package com.dnbns.network;


import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkChecker {
	Context cont;
	Activity act;
	public boolean isUseNetwork (Context cont, Activity act) {
		boolean isTrue = false;
		if(isMobile(act) || isWifi(act) || isWiBro(act) || isWIMAX(act)){
			isTrue = true;
		}
    	return isTrue;
	}
		
	public boolean isMobile(Activity act){
		boolean result = false;
		
		try{
			ConnectivityManager connectivityManager = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
			result = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
		}catch(Exception ex1){
			
		}
		return result;
	}
	
	/**
	 * 단말기가 Wifi에 연결되어있는지를 판단한다.
	 * 
	 * @param Context
	 * @return true: 연결  false: 단절
	 */		
	public boolean isWifi(Activity act){
		ConnectivityManager connectivityManager = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);

		return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
	}	
	
	/**
	 * 단말기가 WiBro(Mobile WiMAX) 에 연결되어있는지를 판단한다.
	 * 
	 * @param Context
	 * @return true: 연결  false: 단절
	 */		
	public boolean isWiBro(Activity act){
		/*
		ConnectivityManager cm = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
		if(cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX) != null 
			&& cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX).getState() == NetworkInfo.State.CONNECTED){
			return true;
		}*/
		return false;
	}		
	
	public boolean isWIMAX(Activity act){
		
		ConnectivityManager cm = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
		if(cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX) != null 
			&& cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX).getState() == NetworkInfo.State.CONNECTED){
			return true;
		}else{
			return false;
		}
	
//		ConnectivityManager connectivityManager = (ConnectivityManager) act.getSystemService(Context.CONNECTIVITY_SERVICE);
//		return connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIMAX).isConnected();		
	}	
}
